package jp.bluecab.bluecabsystem.common;

import java.text.NumberFormat;

public class CommonFunc {
	
	public static long getLong(String str) {
		return getLongDef(str, 0);
	}
	
	public static long getLongDef(String str, long def) {
		long result = def;
		NumberFormat nf = NumberFormat.getInstance();
		try {
			result = nf.parse(str).longValue();
		} catch (Exception e) {
			return def;
		}
		return result;
	}
	
	public static int getInt(String str) {
		return getIntDef(str, 0);
	}
	
	public static int getIntDef(String str, int def) {
		int result = def;
		NumberFormat nf = NumberFormat.getInstance();
		try {
			result = nf.parse(str).intValue();
		} catch (Exception e) {
			return def;
		}
		return result;
	}
	
	public static String getString(String str) {
		String result = "";
		if (str != null) {
			return str;
		}
		return result;
	}
	
	public static String getString(Object obj) {
		if (obj == null) return "";
		return String.valueOf(obj);
	}
}
